import com.alibaba.fastjson.JSON;
import com.baidu.unbiz.fluentvalidator.Result;
import com.tc.qichacha.beneficiary.Beneficiary;
import com.tc.qichacha.beneficiary.BreakThrough;
import com.tc.qichacha.beneficiary.DetailInfo;
import com.tc.qichacha.detail.DetailResult;
import com.tc.qichacha.detail.Details;
import com.tc.qichacha.stock.Stock;
import com.tc.qichacha.stock.StockAnalysisData;
import com.tc.qichacha.validator.BaseResponseValidator;
import com.tc.utils.ToolsHt;
import com.tc.utils.image.table.Table;
import com.tc.utils.image.tree.RectNode;
import lombok.extern.java.Log;
import org.junit.Test;

import java.util.List;

@Log
public class test5 {

    @Test
    public void demo4() throws Exception {
        StockAnalysisData stockAnalysisData = JSON.parseObject(ToolsHt.respond("E:/json.txt"), StockAnalysisData.class);
        Result validatResult = ToolsHt.validateByCustomAndJSR303(stockAnalysisData, new BaseResponseValidator());
        if (!validatResult.isSuccess()) {
            log.info(validatResult.toString());
            return;
        }
        Stock stockList = stockAnalysisData.getResult().getStockList();
        RectNode rectNode = ToolsHt.eachChildren(stockList);
        //rectNode.write("d:/tree.jpg");
        System.out.println(stockAnalysisData);
    }

    @Test
    public void demo5() throws Exception {
        Details detail = JSON.parseObject(ToolsHt.respond("E:/json1.txt"), Details.class);
        Result validatResult = ToolsHt.validateByCustomAndJSR303(detail, new BaseResponseValidator());
        if (!validatResult.isSuccess()) {
            log.info(validatResult.toString());
            return;
        }
        System.out.println(detail);
        System.out.println(detail.getOrderNumber());
        System.out.println(detail.getMessage());
        System.out.println(detail.getStatus());
        if ("200".equals(detail.getStatus())) {
            System.out.println("响应成功");
        }
        DetailResult result = detail.getResult();
        Table table = new Table(2);
        table.appendRow().setCellText("企业名称").setCellText(result.getName());
        table.appendRow().setCellText("法人名称").setCellText(result.getOperName());
        table.appendRow().setCellText("成立日期").setCellText(result.getStartDate());
        table.appendRow().setCellText("企业状态").setCellText(result.getStatus());
        table.appendRow().setCellText("注册号").setCellText(result.getNo());
        table.appendRow().setCellText("社会统一信用代码").setCellText(result.getNo());
        table.write("d:/table.jpg");
    }

    @Test
    public void demo8() throws Exception {
        Details detail = JSON.parseObject(ToolsHt.respond("E:/json1.txt"), Details.class);
        Result validatResult = ToolsHt.validateByCustomAndJSR303(detail, new BaseResponseValidator());
        if (!validatResult.isSuccess()) {
            log.info(validatResult.toString());
            return;
        }
        System.out.println(detail);
        System.out.println(detail.getOrderNumber());
        System.out.println(detail.getMessage());
        System.out.println(detail.getStatus());
        if ("200".equals(detail.getStatus())) {
            System.out.println("响应成功");
        }
        DetailResult result = detail.getResult();
        Table table = new Table(2);
        table.appendRow().setCellText("企业名称").setCellText(result.getName());
        table.appendRow().setCellText("法人名称").setCellText(result.getOperName());
        table.appendRow().setCellText("成立日期").setCellText(result.getStartDate());
        table.appendRow().setCellText("企业状态").setCellText(result.getStatus());
        table.appendRow().setCellText("注册号").setCellText(result.getNo());
        table.appendRow().setCellText("社会统一信用代码").setCellText(result.getNo());
        table.write("d:/table.jpg");
    }

    @Test
    public void demo6() throws Exception {
        Beneficiary beneficiary = JSON.parseObject(ToolsHt.respond("E:/json2.txt"), Beneficiary.class);
        Result validatResult = ToolsHt.validateByCustomAndJSR303(beneficiary, new BaseResponseValidator());
        if (!validatResult.isSuccess()) {
            log.info(validatResult.toString());
            return;
        }
        List<BreakThrough> breakThroughList = beneficiary.getResult().getBreakThroughList();
        Table table = new Table(4);
        table.appendRow().setCellText("序号").setCellText("最终受益人名称").setCellText("持股比例").setCellText("股权链");
        for (int i = 0; i < breakThroughList.size(); i++) {
            BreakThrough breakThrough = breakThroughList.get(i);
            List<DetailInfo> detailInfoList = breakThrough.getDetailInfoList();
            if (detailInfoList == null || detailInfoList.isEmpty()) {
                log.info("detailInfo:为空");
                table.appendRow().setCellText(String.valueOf(i + 1)).setCellText(breakThrough.getName()).setCellText(breakThrough.getTotalStockPercent())
                        .setCellText("");
            } else {
                for (DetailInfo detailInfo : detailInfoList) {
                    table.appendRow().setCellText(String.valueOf(i + 1)).setCellText(breakThrough.getName()).setCellText(breakThrough.getTotalStockPercent())
                            .setCellText(detailInfo.getPath());
                }
            }
        }
        table.write("d:/table.jpg");
    }
}
